package com.qubuyer.business.home.presenter

import com.qubuyer.base.mvp.WrapperPresenter
import com.qubuyer.repository.entitys.HomeGoodEntity
import com.qubuyer.business.home.view.ILimitBuyView
import com.qubuyer.business.home.presenter.ILimitBuyPresenter
import com.qubuyer.business.home.model.ILimitBuyModel
import com.qubyer.okhttputil.helper.ServerResponse
import com.qubyer.okhttputil.utils.HttpConstant
import com.qubuyer.business.home.model.LimitBuyModel
import java.util.ArrayList

class LimitBuyPresenter : WrapperPresenter<ILimitBuyView?>(), ILimitBuyPresenter {

    init {
        mModel = LimitBuyModel(this)
        attachModel(mModel)
    }
    override fun loadLimitBuyData() {
        mView!!.showLoading()
        (mModel as LimitBuyModel).loadLimitBuyData()
    }

    override fun onLoadLimitBuyData(serverResponse: ServerResponse) {
        mView!!.hideLoading()
        mView!!.doResponseError(serverResponse.code, serverResponse.message)
        if (serverResponse.code == HttpConstant.Status.SERVER_STATUS_SUCCESSFUL && null != serverResponse.result) {
            mView!!.onShowLimitBuyDataToView(serverResponse.time, serverResponse.result as List<HomeGoodEntity?>)
        } else {
            mView!!.onShowLimitBuyDataToView(serverResponse.time, ArrayList(0))
        }
    }


}